package com.honghu.villagepost.util;

import android.widget.ImageView;

import com.honghu.villagepost.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * @author: mqwang
 * @create: 2/19/21 5:55 PM
 * @Description:
 */
public class GlideUtil {

    public static void loadImg(ImageView iv, String url){
        Glide.with(iv.getContext()).load(url).centerCrop().apply(new RequestOptions().error(R.drawable.bg_cat_grey).placeholder(R.drawable.bg_cat_grey)).into(iv);
    }

    public static void loadCircleImg(ImageView iv, String url){
        Glide.with(iv.getContext()).asBitmap().load(url).apply(new RequestOptions().placeholder(R.drawable.bg_cat_grey).transform(new CircleCrop())).into(iv);
    }

    public static void loadNoneImg(ImageView iv, String url){
        Glide.with(iv.getContext()).load(url).apply(new RequestOptions().error(R.drawable.bg_cat_grey).placeholder(R.drawable.bg_cat_grey)).into(iv);
    }

    /**
     * Desc:加载图片圆角
     * <p>
     * Author: [李豫]
     * Date: 2021-07-15
     *
     * @param iv
     * @param url
     * @param radius
     */
    public static void loadImg(ImageView iv, String url, int radius){
        Glide.with(iv.getContext())
                .load(url)
                .centerCrop()
                .apply(new RequestOptions()
                        .transform(new RoundedCornersTransformation(radius, 0))
                        .error(R.drawable.bg_cat_grey)
                        .placeholder(R.drawable.bg_cat_grey))
                .into(iv);
    }
}
